"use strict";
const dbTool = require("../utils/db");
const Suite = require("mongoose").model("Suite");


const updateSuiteBySuiteKey = function(suiteKey, updateInfo) { //ticket是跟suitekey走的，每个org的suite ticket都一样
	const condition = {
		suiteKey
	};
	const update = {
		$set: {
			vendorKey: updateInfo.vendorKey,
			suiteTicket: updateInfo.suiteTicket,
			_id: suiteKey
		}
	};
	const option = {
		upsert: true //当用户创建一个套件之后，会马上推送套件的ticket，此时需要初始化这个套件
	};
	console.log("更新ticket的参数是", condition, update);
	return Suite.update(condition, update, option).catch(e => console.error(e));
};
const getSuiteByKey = function(suiteKey) {
	const condition = {
		suiteKey
	};
	Object.assign(condition, this);
	console.log("查询参数是", condition);
	return Suite.findOne(condition).exec().then(dbTool.toSimpleteObject);
};



module.exports = {
	updateSuiteBySuiteKey,
	getSuiteByKey
};